package com.cai.servlet.common.topic;

import com.cai.dao.DetailedTopicDao;
import com.cai.dao.impl.DetailedTopicDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author RuoLi
 * 用户端展示题目信息
 */
@WebServlet(name = "ServletDetailedTopicInfoShow", value = "/common/detailedTopicInfoShow")
public class ServletShowTopicInfo extends HttpServlet {
    DetailedTopicDao detailedTopicDao = new DetailedTopicDaoImpl();
    int currentPage = 1;
    int pageSize = 10;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String showTopicData = detailedTopicDao.getDetailedTopicInfoUserClient(currentPage, pageSize);
        resp.getWriter().write(showTopicData);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        currentPage = Integer.parseInt(req.getParameter("currentPage"));
        pageSize = Integer.parseInt(req.getParameter("pageSize"));
        String showTopicData = detailedTopicDao.getDetailedTopicInfoUserClient(currentPage, pageSize);
        resp.getWriter().write(showTopicData);
    }
}
